﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HistogramPackage {
    public abstract class PDF {

        public List<Variable> greeks; // stores the greeks used by the particular function
        protected double alpha; // these are only initialized right before an output is generated
        protected double beta;
        protected double gamma;
        protected double theta;
        protected double tau;
        protected double sigma;
        protected double mu;
        public string name;

        public string lnFunction;
        public string function;
        public abstract double getOutput(double x);
        public abstract double getMoment(double k);
        public abstract double parametricVolume(double x);

        public enum Greek { ALPHA, BETA, GAMMA, THETA, TAU, SIGMA, MU, ALPHA2, BETA2, GAMMA2, THETA2, TAU2, SIGMA2, MU2 };

        public PDF() {
            greeks = new List<Variable>();
        }

        public string getGreeks() {
            string temp = "";
            foreach (Variable var in greeks) {
                temp += var.type + "\t" + var.value + "\n";
            }
            return temp;
        }

        public static double standardNormal(double x) {
            double denominator1 = Math.Exp(-1 / 2 * Math.Pow(x, 2));
            double fullDenomerator = Math.Pow(Math.Sqrt(2 * Math.PI), denominator1);
            return 1 / fullDenomerator;
        }

        // this reduces alot of code in the subclasses
        public void extractGreekValues() {
            alpha = double.NaN;
            beta = double.NaN;
            gamma = double.NaN;
            theta = double.NaN;
            tau = double.NaN;
            sigma = double.NaN;
            mu = double.NaN;

            foreach (Variable var in greeks) {
                Greek type = var.type;
                double value = var.value;
                if (type == Greek.ALPHA) {
                    alpha = value;
                }
                else if (type == Greek.BETA) {
                    beta = value;
                }
                else if (type == Greek.GAMMA) {
                    gamma = value;
                }
                else if (type == Greek.THETA) {
                    theta = value;
                }
                else if (type == Greek.TAU) {
                    tau = value;
                }
                else if (type == Greek.SIGMA) {
                    sigma = value;
                }
                else if (type == Greek.MU) {
                    mu = value;
                }
            }
        }

        public class Variable {
            public Greek type;
            public double value;
        }
    }
}
